package com.lrkj.smartservice.controller;

import java.util.List;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.smartservice.domain.PressType;
import com.lrkj.smartservice.service.IPressTypeService;

/**
 * 新闻分类Controller
 * 
 * @author yajun_ren
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/smartservice/pressType")
public class PressTypeController extends BaseController
{
    @Autowired
    private IPressTypeService pressTypeService;

    /**
     * 查询新闻分类列表
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressType:list')")
    @GetMapping("/list")
    public TableDataInfo list(PressType pressType)
    {
        startPage();
        List<PressType> list = pressTypeService.selectPressTypeList(pressType);
        return getDataTable(list);
    }

    /**
     * 导出新闻分类列表
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressType:export')")
    @Log(title = "新闻分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PressType pressType)
    {
        List<PressType> list = pressTypeService.selectPressTypeList(pressType);
        ExcelUtil<PressType> util = new ExcelUtil<PressType>(PressType.class);
        return util.exportExcel(list, "pressType");
    }

    /**
     * 获取新闻分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressType:query')")
    @GetMapping(value = "/{pressTypeId}")
    public AjaxResult getInfo(@PathVariable("pressTypeId") String pressTypeId)
    {
        return AjaxResult.success(pressTypeService.selectPressTypeById(pressTypeId));
    }

    /**
     * 新增新闻分类
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressType:add')")
    @Log(title = "新闻分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PressType pressType)
    {
        return toAjax(pressTypeService.insertPressType(pressType));
    }

    /**
     * 修改新闻分类
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressType:edit')")
    @Log(title = "新闻分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PressType pressType)
    {
        return toAjax(pressTypeService.updatePressType(pressType));
    }

    /**
     * 删除新闻分类
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressType:remove')")
    @Log(title = "新闻分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pressTypeIds}")
    public AjaxResult remove(@PathVariable String[] pressTypeIds)
    {
        return toAjax(pressTypeService.deletePressTypeByIds(pressTypeIds));
    }
}
